<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>菜单信息页面</title>
<link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="css/public.css" media="all">
<style>
.layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
	height: 34px;
	line-height: 34px;
	padding: 0 8px;
}
</style>
</head>
<body>
	<div class="layuimini-container">
		<div class="layuimini-main">
			<div>
				<div class="layui-btn-group">
					<button class="layui-btn " id="btn-expand">全部展开</button>
					<button class="layui-btn " id="btn-fold">全部折叠</button>
					<span style="padding-left: 773px;"><button class="layui-btn layui-btn-normal" id="btn-fatheradd" >添加父管理</button></span>
				</div>
				<table id="munu-table" class="layui-table" lay-filter="munu-table"></table>
			</div>
		</div>
	</div>
	<!-- 操作列 -->
	<script type="text/html" id="auth-state">
	{{# if(d.parentId < 0){ }} 
	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add">添加子页面</a>
    <a class="layui-btn layui-btn-warm   layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	{{# } else { }}
    <a class="layui-btn layui-btn-warm   layui-btn-xs" lay-event="edit">修改</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	{{# } }}
</script>

	<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
	<script src="js/Global.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/lay-config.js?v=1.0.4" charset="utf-8"></script>
	<script>
		layui.use([ 'table', 'treetable' ], function() {
			var $ = layui.jquery;
			var table = layui.table;
			var treetable = layui.treetable;

			// 渲染表格
			layer.load(2);
			treetable.render({
				treeColIndex : 1,
				treeSpid : -1,
				treeIdName : 'id',
				treePidName : 'parentId',
				elem : '#munu-table',
				url : globalData.server + 'public/getAllMenus',
				page : false,
				cols : [ [ {
					type : 'numbers',
					fixed : 'left',
					align:'center'
				}, {
					field : 'title',
					minWidth : 200,
					title : '菜单名称'
				}, {
					field : 'menuurl',
					title : '菜单路径'
				}, {
					field : 'menusort',
					align : 'center',
					title : '菜单权重'
				}, {
					field : 'icon',
					align : 'center',
					title : '菜单图标'
				}, {
					templet : '#auth-state',
					width : 230,
					fixed : 'right',
					align : 'right',
					title : '操作'
				} ] ],
				done : function() {
					layer.closeAll('loading');
				}
			});

			$('#btn-expand').click(function() {
				treetable.expandAll('#munu-table');
			});

			$('#btn-fold').click(function() {
				treetable.foldAll('#munu-table');
			});
			$('#btn-fatheradd').click(function() {
				var index = layer.open({
					title : '添加父级菜单',
					type : 2,
					shade : 0.2,
					maxmin : true,
					shadeClose : true,
					area : [ '550px', '510px' ], //页面的宽高
					content : 'Menus_add.html',
					success : function(layero, index) {
						var body = layer.getChildFrame('body', index);
						body.find("#menufatherid").val(-1);
					},
					end : function() {
						window.location.reload();
					}
				});
				$(window).on("resize", function() {
					layer.full(index);
				});
			});
			//监听工具条
			table.on('tool(munu-table)', function(obj) {
				var data = obj.data;
				var layEvent = obj.event;
				console.log(data);
				if (layEvent === 'del') {
					layer.confirm('确定要删除' + data.title + '吗?', function(index) {
						$.post(globalData.server + "public/deleteMenus", {
							"menuid" : data.id
						}, function(res) {
							if (res.count > 0) {
								layer.msg("删除成功", {
									icon : 1,
									time : 3000
								});
								obj.del();
							} else {
								layer.msg("刪除失败，该模块下有角色的分配！！！", {
									icon : 2,
									time : 3000
								})
							}
						}, "json");
						layer.close(index);
					});
				} else if (layEvent === 'edit') {
					var index = layer.open({
						title : '修改' + data.title,
						type : 2,
						shade : 0.2,
						maxmin : true,
						shadeClose : true,
						area : [ '550px', '510px' ], //页面的宽高
						content : 'Menus_edit.html',
						success : function(layero, index) {
							var body = layer.getChildFrame('body', index);
							body.find("#menuid").val(data.id);
							body.find("#menuname").val(data.title);
							body.find("#menufatherid").val(data.parentId);
							body.find("#menuurl").val(data.menuurl);
							body.find("#menusort").val(data.menusort);
							body.find("#icon").val(data.icon);
						},
						end : function() {
							window.location.reload();
						}
					});
					$(window).on("resize", function() {
						layer.full(index);
					});
				} else if (layEvent === 'add') {
					var index = layer.open({
						title : '添加' + data.title + '下的子页面',
						type : 2,
						shade : 0.2,
						maxmin : true,
						shadeClose : true,
						area : [ '550px', '510px' ], //页面的宽高
						content : 'Menus_add.html',
						success : function(layero, index) {
							var body = layer.getChildFrame('body', index);
							body.find("#menufatherid").val(data.id);
						},
						end : function() {
							window.location.reload();
						}
					});
					$(window).on("resize", function() {
						layer.full(index);
					});
				}
			});
		});
	</script>
</body>
</html>